const Koa = require('koa')
const router = require('koa-router')()
const render = require('koa-art-template')
const path = require('path')

// 实例化
const app = new Koa()

// 配置art模板引擎
render(app, {
  root: path.join(__dirname, 'views'), //视图的位置
  extname: '.html', //后缀名 
  debug: process.env.NODE_ENV !== 'production' //是否开启调试模式
})


//路由配置
router.get('/', async (ctx) => {
  const data = { 
    name:'limi',
    h: '<h3>这是一个h3</h3>',
    num: 20
  }
  const list = [111, 222, 333]
  await ctx.render('index', {
    data,
    list
  })
})

router.get('/news', async (ctx) => {
  const data = { 
    name:'limi',
    h: '<h3>这是一个h3</h3>',
    num: 20
  }
  const list = [111, 222, 333]
  await ctx.render('news', {
    data,
    list
  })
})

//启动路由
app.use(router.routes())
app.use(router.allowedMethods())
app.listen(3000)